FROM alpine:3.8

# 解决系统中文显示乱码问题
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

# 拷贝jdk安装包，使用ADD命令无效
COPY jdk-8u181-linux-x64.tar.gz /tmp/jdk-8u181-linux-x64.tar.gz 
# 创建服务需要的目录，详情参考http://172.17.1.10:8090/pages/viewpage.action?pageId=327684记录
RUN mkdir /opt/app/logs /opt/case/hexin/seal /opt/case/hexin/bill /home/b2b2p/membercenter /opt/case/secret/v1 -p && \
    tar -zxvf /tmp/jdk-8u181-linux-x64.tar.gz -C /opt > : && \ 
    rm -rf /tmp/* && \
    # 创建金融服务需要的密钥文件
    echo "cf410f84904a44cc8a7f48fc4134e8f9" > /home/b2b2p/membercenter/deskey.txt && \
    # 创建风控服务需要的密钥文件
    echo "cf410f84904a44cc8a7f48fc4134e8f9" > /opt/case/secret/v1/des.key

# 拷贝产品核心需要的配置文件
COPY b2b2p /home/b2b2p

# Alpine安装 Glibc https://github.com/sgerrand/alpine-pkg-glibc, java运行需要glibc
# dosfstools是dos2unix转换工具
# 解决系统中文显示乱码问题
RUN sed -i 's#dl-cdn.alpinelinux.org#mirrors.aliyun.com#g' /etc/apk/repositories && \
    apk update && \
    apk --no-cache add ca-certificates dosfstools tzdata && \
    wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \
    wget -O /tmp/glibc-2.28-r0.apk https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk && \
    apk add /tmp/glibc-2.28-r0.apk && rm /tmp/glibc-2.28-r0.apk && \
    wget -q -O glibc-bin-2.28-r0.apk https://github.com/sgerrand/alpine-pkg-glibc/releases/download/unreleased/glibc-bin-2.28-r0.apk && \
    wget -q -O glibc-i18n-2.28-r0.apk https://github.com/sgerrand/alpine-pkg-glibc/releases/download/unreleased/glibc-i18n-2.28-r0.apk && \
    # 更换本机时间、修改时区，移除tzdata，关于本机时间和时区的修改参考https://blog.csdn.net/xinluke/article/details/52182858，待确认时区是否要修改
    cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone && echo "Asia/Shanghai" > /etc/timezone && \ 
    apk del tzdata && apk add glibc-bin-2.28-r0.apk glibc-i18n-2.28-r0.apk && /usr/glibc-compat/bin/localedef -i en_US -f UTF-8 en_US.UTF-8

# 配置jdk环境变量
ENV JAVA_HOME=/opt/jdk1.8.0_181
ENV CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar 
ENV PATH=$JAVA_HOME/bin:$HOME/bin:$HOME/.local/bin:$PATH

WORKDIR /opt/app